package servlet.user;

import bean.Result;
import biz.BizException;
import biz.PersonalBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SavePersonalCenterServlet", value = "/SavePersonalCenterServlet.s")
public class SavePersonalCenterServlet extends HttpServlet {
    private PersonalBiz biz = new PersonalBiz();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uid = request.getParameter("uid");
        String name = request.getParameter("uname");
        String sex = request.getParameter("sex");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        System.out.println(uid);
        Result result;

        try {
                biz.modifyUser(name,phone,email,uid);
            result = new Result(1, "保存成功！", null);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0, e.getMessage(), null);
        }
        System.out.println(result);
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
